package com.example.xd.phone_album

import android.os.Parcel
import android.os.Parcelable

/**
 * @auther XuDan on 2020/8/13.
 */
data class SingleImageModel(
    var path: String?,
    var isSelect: Boolean = false,
    var date: Long,
    var id: Long,
    var type: Int,
    var mime_type: String?,
    var ordinal: Int = -1
) : Parcelable {
    constructor() : this("", false, 1, 1, 1, "", -1) {}

    constructor(source: Parcel) : this(
        source.readString(),
        1 == source.readInt(),
        source.readLong(),
        source.readLong(),
        source.readInt(),
        source.readString(),
        source.readInt()
    )

    override fun describeContents() = 0

    override fun writeToParcel(dest: Parcel, flags: Int) = with(dest) {
        writeString(path)
        writeInt((if (isSelect) 1 else 0))
        writeLong(date)
        writeLong(id)
        writeInt(type)
        writeString(mime_type)
        writeInt(ordinal)
    }

    companion object {
        val TYPE_PIC: Int = 0

        val TYPE_VIDEO = 1

        @JvmField
        val CREATOR: Parcelable.Creator<SingleImageModel> =
            object : Parcelable.Creator<SingleImageModel> {
                override fun createFromParcel(source: Parcel): SingleImageModel =
                    SingleImageModel(source)

                override fun newArray(size: Int): Array<SingleImageModel?> = arrayOfNulls(size)
            }
    }
}